package cn.add.ui;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import cn.add.R;
import cn.add.cache.CacheManage;
import cn.add.model.Battery;
import cn.add.model.Signal;
import cn.add.util.DrawUtil;

public class Panel extends Component{
	
	private BatteryImage mBatteryImage;
	private SignalImage mSignalImage;
	
	private Battery mBattery;
	private Signal mSignal;
	
	//充电状态图片位置
	private final int loadingPosition = R.drawable.bg2;
	
	//不是充电状态图片位置
	private final int defaultPosition = R.drawable.bg1;
	
	private Paint mPaint;
	

	public Panel(Context ctx,Battery battery,Signal signal){
		super(ctx);
		mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		mPaint.setTextSize(20);
		mPaint.setColor(Color.WHITE);
		mPaint.setTypeface(Typeface.DEFAULT_BOLD);
		mBattery = battery;
		mSignal = signal;
		mBatteryImage = new BatteryImage(ctx,battery);
		mSignalImage = new SignalImage(ctx,signal);
	}
	
	@Override
	protected void onDraw(Canvas mCanvas) {
		drawBG(mCanvas);
		mBatteryImage.draw(mCanvas);
		mSignalImage.draw(mCanvas);
		mCanvas.drawText("level = " + mBattery.getMLevel() + " ---> status = " + mBattery.getMStatus(),50,80,mPaint);
		mCanvas.drawText("level = " + mSignal.getASU(),50,100,mPaint);
	}
	
	//负责画背景
	private void drawBG(Canvas mCanvas){
		int batteryStatus = mBattery.getMStatus();
		Bitmap mBitmap;
		if(batteryStatus == 2){
			mBitmap = CacheManage.getBitmap(loadingPosition, R.drawable.bg2);
		}else{
			mBitmap = CacheManage.getBitmap(defaultPosition, R.drawable.bg1);
		}
		DrawUtil.drawBitmap(mCanvas, mBitmap, 0, 0, null);
	}
}
